#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans1=1e18,ans2=1e18,ans3=1e18;
struct node{
	int a,b;
}a[100010];
bool cmp(node p,node q){
	return p.b<q.b;
}
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&a[i].a,&a[i].b);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		ans3=min(ans3,ans2+a[i].a+a[i].b),ans2=min(ans2,ans1+a[i].a+a[i].b),ans1=min(ans1,a[i].a);
	printf("%lld",ans3);
	return 0;
}
